import java.util.Arrays;

public class 课上练习 {
    public static int[] reverse(int[] s) {
        int i = 0;
        int j = s.length - 1;
        while (i < j) {
            int tmp = s[j];
            s[j] = s[i];
            s[i] = tmp;
            i++;
            j--;
        }
        return s;
    }
    public static void main(String[] args) {
        //写一个方法使数组倒序打印
        int[] arrey = {1,23,45,67,89};
        int[] kk = reverse(arrey);
        String i = fun(kk);
        System.out.println(i);

    }
    public static String fun(int[] arr) {
        String k = "[";
        for (int i = 0; i < arr.length; i++) {
            //System.out.print(arr[i] + ",");
            k += arr[i];
            if (i < arr.length - 1) {
                k += ",";
            }
        }
        k += "]";
        return k;
    }
    public static void main6(String[] args) {
        //自己 写一个
        // 方法实现程序化输出
        int[] arrey = {1,2,3,4,5};
        String i = fun(arrey);
        System.out.println(i);

    }
    public static int[] func() {
        return new int[]{1,2,3,4,5};
    }
    public static void main5(String[] args) {
        //创建数组方法
        int[] r = func();
        System.out.println(r);
        for (int i = 0; i < r.length; i++) {
            System.out.println(r[i]);
        }

    }




    public static void main4(String[] args) {
        int[]array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;


        int[] array2 = new int[]{1,2,3,4,5};
        array2[1] = 100;
        array2[2] = 200;


        array1 = array2;//使得array1原有的对象丢失
        array1[2] = 100;
        array2[3] = 200;
        array2[4] = 300;
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i] + " ");
        }

    }
    public static void main3(String[] args) {
        //将一整个数组输出
        int[] add = {1,2,3,4,5};
        for (int i = 0; i < add.length; i++) {//add。length代表的是数组的长度
            System.out.print(add[i] + " ");
        }
        System.out.println();
        System.out.println("-------------------");
        for (int i : add ) {
            add[2] = 22;
            System.out.println(i + " ");//无法知道数组的索引，不知道元素在数组中是第几个, 打印字符串


        }
        String ret = Arrays.toString(add);//格式化输出， 括号也输出了出来
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        boolean[] el = new boolean[5];
        System.out.println(el[2]);//静态值是false
        String[] ee = new String[3];
        System.out.println(ee[2]);//无对象值null
    }
    public static void main1(String[] args) {
        //数组
        int[] str = {1,2,3,4,5};
        //System.out.println(str[1]);
        //中括号输出， 对数组排序
        str[0] = 10;
        System.out.println(str[0]);
        System.out.println(str);//只是输出了相应的编码值
        int[] arr = new int[8];//静态赋值
        System.out.println(arr[2]);//不是存入随机值，而是0；


    }
}
